File LastAccessTime

Summary description for File_LastAccessTime

C# .NET

public static String DoTest()
{
         string strRet = "";
         try
         {
                  string path = @"c:\MyFile.txt";
                  // Create the file; if it does not exist.
                  if (!File.Exists(path))
                  {
                           StreamWriter sw = File.CreateText(path);
                           sw.WriteLine("Hello");
                           sw.Close();
                  }
                  File.SetLastAccessTime(path, new DateTime(1985,5,4));

                  // Get the creation time of the file
                  DateTime dt = File.GetLastAccessTime(path);
                  strRet += String.Format("The last access time for the file was {0}\r\n", dt);

                  // Update the last access time.
                  File.SetLastAccessTime(path, DateTime.Now);
                  dt = File.GetLastAccessTime(path);
                  strRet += String.Format("The last access time for the file was {0}\r\n", dt);
         }
         catch (Exception e)
         {
                  strRet += String.Format("The process failed: {0}\r\n", e.ToString());
         }
         return strRet;
         
}

 

Blaze++ .NET

static String DoTest()
{
         String strRet = "";
         try
         {
                  String path = "c:\\MyFile.txt";
                  // Create the file; if it does not exist.
                  if (!File::Exists(path))
                  {
                           StreamWriter sw = File::CreateText(path);
                           sw.WriteLine("Hello");
                           sw.Close();
                  }
                  File::SetLastAccessTime(path, DateTime(1985,5,4));

                  // Get the creation time of the file
                  DateTime dt = File::GetLastAccessTime(path);
                  strRet += String::Format("The last access time for the file was {0}\r\n", dt);

                  // Update the last access time.
                  File::SetLastAccessTime(path, DateTime::Now);
                  dt = File::GetLastAccessTime(path);
                  strRet += String::Format("The last access time for the file was {0}\r\n", dt);
         }
         catch (Exception e)
         {
                  strRet += String::Format("The process failed: {0}\r\n", e.ToString());
         }
         return strRet;
}